package study.eggs.validation.factory;

import study.eggs.validation.constraints.NotEmpty;
import study.eggs.validation.constraints.Number;
import study.eggs.validation.validator.NotEmptyValidator;
import study.eggs.validation.validator.NumberValidator;
import study.eggs.validation.validator.Validator;

import java.lang.annotation.Annotation;

public class ValidatorFactory {

     public static Validator getValidator(Annotation annot) {
          Validator validator;
          if (annot instanceof NotEmpty) {
               validator = new NotEmptyValidator();
          } else if (annot instanceof Number) {
               validator = new NumberValidator();
          } else {
               throw new IllegalStateException("不支持的约束！");
          }
          return validator;
     }
}
